package com.test.controller;

import com.test.po.Admins;
import com.test.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class AdminController {
    @Autowired
    private AdminService adminService;
    @RequestMapping("/adlogin.do")
    public String adlogin(String adminname, String adminpwd, ModelMap map){
        System.out.println(adminname);
        Admins admins = adminService.findByAdminsname(adminname);

        System.out.println(admins);
        if(admins != null){
            if (admins.getAdminpwd().equals(adminpwd)){
                System.out.println("login success");
                map.addAttribute("adminname",admins.getAdminname());
                map.addAttribute("adminid",admins.getAdminid());
                return "adindex";
            }else{
                System.out.println("wrong password");
                return "forward:adlogin.jsp";
            }
        }else{
            System.out.println("admin not exist");
            return "forward:adlogin.jsp";
        }
    }


}
